/**
 * Created by LeungZ on 2016/9/7.
 */
class Add {
    constructor(clusterSrv,item, $modalInstance, ctgNotification) {
        "ngInject"
        this.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
        if(item){//编辑
            this.formdata={
           name: item.clusterName,
           code: item.clusterCode,
           addr: item.monitorUrl,
           lvs: item.lvsUrl,
           id:item.id
            };
        }else{
            this.formdata={
                id:null    
            }
        }

        this.save = ()=> {
            this.loading = true;
            var sucMsg='新增容器集群 '+this.formdata.name+' 成功.',
                errorMsg='新增容器集群失败,';
              if(item){
                    sucMsg='编辑容器集群 '+this.formdata.name+' 成功.';
                    errorMsg='编辑容器集群失败,'
                }
            clusterSrv.addCluster(this.formdata).then(data=> {
                $modalInstance.close();
              
                ctgNotification.success(sucMsg);
            }).catch(function(data) {
                ctgNotification.error(errorMsg + data.resultMsg);
            }).finally(()=>{
                this.loading = false;
            });
        }
    }
}
export default Add